<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>查看用户</title>
</head>
<body>
<jsp:include page="/incloud/header.jsp" />

<div class="d-flex align-items-stretch">
    <!-- Sidebar Navigation-->
    <jsp:include page="/incloud/sidebar.jsp" />
    <!-- Sidebar Navigation end-->
    <div class="page-content">
        <div class="page-header">
            <div class="container-fluid">
                <h2 class="h5 no-margin-bottom">用户列表</h2>
            </div>
        </div>
        <section class="no-padding-bottom">
            <div class="title">
                <form class="form-inline" action="/internal/findPage">
<%--                    从第一页开始，不然会出现类型转换异常--%>
                    <input type="hidden" name="currPage" value="1">

                    <div class="form-group">
                        <label for="inlineFormInput" class="sr-only">Name</label>
                        <input id="inlineFormInput" name="realName"  value="${realName}" type="text" placeholder="按名字查找" class="mr-sm-3 form-control">
                    </div>
                    <div class="form-group">
                        <input type="submit" id="inlineFormButton" value="查询" class="btn btn-primary">
                    </div>
                </form>

            </div>
            <div class="table-responsive">
                <table class="table">
                    <thead>
                    <tr>
                        <th>ID</th>
                        <th>姓名</th>
                        <th>性别</th>
                        <th>年龄</th>
                        <th>简介</th>
                        <th>操作</th>
                        <th>加关注</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach items="${pageEntity.data}" var="user">
                    <tr>
                        <th scope="row">${user.id}</th>
                        <td>${user.realName}</td>
                        <td>${user.gender == 0?'女':'男'}</td>
                        <td>${user.age}</td>
                        <td>${user.info}</td>
                        <td>
                            <input id="otherInfo" onclick=" otherInfo(${user.id},${user.isSecret})" type="button" value="详细信息" class="btn-xs btn-primary userDetail">
                        </td>

                        <td>
            
                            <input type="checkbox" value="" class="checkbox-template"
                                   onclick="addFocus(${user.id},event)" ${FocusIdList.contains(user.id)?'checked':''}>
            
                        </td>
                    </tr>
                    </c:forEach>
                    </tbody>
                </table>
            
                <nav class="text-center" aria-label="Page navigation">
                    <ul class="pagination">
                        <li>
                            <a href="#" aria-label="Previous" onclick="pre()" id="pre">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </li>
                        <c:forEach begin="1" end="${pageEntity.totalPage}" varStatus="row">
                        <li><a  ${row.count == pageEntity.currPage?'style="background: #0c5460"':'' }
                                href="/internal/findPage?currPage=${row.count}&realName=${realName}">${row.count}</a></li>
                        </c:forEach>
                        <li>
                            <a href="#" aria-label="Next" onclick="next()" id="next">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                        </li>
                    </ul>
                </nav>
            </div>
        </section>

        <jsp:include page="/incloud/footer.jsp" />
    </div>
</div>

<!-- JavaScript files-->

<script>

    function addFocus(userId,event){
        if ("${loginUser.id}"== userId){
            layer.msg("不能关注自己")
            //取消默认事件
            event.preventDefault()
            return;
        }
        $.post("/internal/focus", {
            "userId": userId,
        }, function (res) {
            if (res == 1) {
                layer.msg("取关成功")
            } else {
                layer.msg("关注成功")
            }
        })

    }
    function otherInfo(userID,isSecret){
        if (isSecret == 0){
            layer.msg("私密用户")
            return;
        }
        window.location.href = "/internal/userDetail?userID="+userID+"&flag=detail"
    }
</script>
<script>
    function pre(){
        if (${pageEntity.currPage-1<=0}){
            layer.msg("已经是第一页了")
            return;
        }
        window.location.href = "/internal/findPage?currPage=${pageEntity.currPage - 1}&realName=${realName}"
    }
    function next(){
        if (${pageEntity.currPage+1 > pageEntity.totalPage}){
            layer.msg("已经是最后一页了")
            return;
        }
        window.location.href = "/internal/findPage?currPage=${pageEntity.currPage + 1}&realName=${realName}"
    }
</script>
<script type="text/javascript">
	
	$(function(){
		
		//用户列表，查看详情，通过class名字userDetail来找
		$("#userDetail").click(function () {
		    console.log("你点击了用户详情");
		    window.location.href = '/html/user_detail.jsp'
		});

		
	})
	
</script>
</body>
</html>
